package com.leetcode.string;

/**
 * @author Dennis Li
 * @date 2020/7/29 10:46
 */
public class CountBinarySubstrings_696 {

    private int count = 0;

    public int countBinarySubstrings(String s) {
        for (int i = 0; i < s.length() - 1; i++) {
            countSub(s, i);
        }
        return count;
    }

    private void countSub(String s, int start) {
        int i = start, j = start + 1;
        char c1 = s.charAt(i), c2 = s.charAt(j);
        // 两个不能超界，并且不能相等
        while (i >= 0 && j < s.length()) {
            char ch1 = s.charAt(i), ch2 = s.charAt(j);
            if(ch1 == ch2 || ch1 != c1 || ch2 != c2) break;
            i--;
            j++;
            count++;
        }
    }

}
